import {safeStringify} from './safeStringify';
export const log = (...args) => {
    console.log('---' + new Date + '---');
    let msg=[];
    for (let i = 0, il = args.length; i < il; i++) {
        if(typeof args[i]==='object'){
            msg.length>0&&console.log(msg.join(' '));
            console.log(args[i]);
            msg=[];
            continue;
        }
        msg.push(args[i]);
    }
    msg.length>0&&console.log(msg.join(' '));
};

export const logReturn = (...args) => {
    log(...args);
    return args[args.length-1];
};
export const logStringify = (...args) => {
    const _args=[];
    for (let i = 0, il = args.length; i < il; i++) {
        if(typeof args[i]==='object'){
            _args.push(safeStringify(args[i]));
            continue;
        }
        _args.push(args[i]);
    }
    return log(..._args);
};
export const logWithTrace = (...args) => {
    log(...args);
    console.trace();
};
//getHome=logFn('getHomeCall',getHome);
export const logFn = function(tip,fn,...logArgs){
    return function (...args) {
        const rst=fn.call(this,...args);
        log(tip,...args,rst,...logArgs);
        return rst;
    }
};
export default log;